<template>
	<view class="pics">
		<scroll-view class="left" scroll-y="true">
			<view @click="leftClickHandle(index,item.id)" :class="active==index?'active':''" v-for="(item,index) in cates" :key="item.id">
			{{item.title}}
			</view>
		</scroll-view>
		<scroll-view class="right" scroll-y="true">
			<view class="item" v-for="item in secondDate" :key="item.id">
				<image @click="previewImg(item.img_url)" :src="item.img_url"></image>
				<text>{{item.title}}</text>
			</view>
			<view v-if="secondDate.length==0">
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/29.JPG"></image>
			<text>图书馆</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/2.jpg"></image>
			<text>山师亭</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/3.jpg"></image>
			<text>长清湖</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/4.jpg"></image>
			<text>操场</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/5.jpg"></image>
			<text>体育场</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/6.jpg"></image>
			<text>教学楼</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/28.jpg"></image>
			<text>春意盎然</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/8.jpg"></image>
			<text>夏日炎炎</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/7.jpg"></image>
			<text>叶落知秋</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/12.jpg"></image>
			<text>雪兆丰年</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/10.jpg"></image>
			<text>校园全景</text>
			</view>
			<view class="text">
			<image mode="aspectFill" src="http://www.sdnu.edu.cn/images/viewimg/15.jpg"></image>
			<text>暗香疏影(梅苑)</text>
			</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:0,
				secondDate:[],
				detail:[]
			}
		},
		methods: {
			async getPicsCate() {
				const res = await this.$myrequest({
					url: '/api/getimgcategory'
				})
				this.cates = res.data.message
				this.leftClickHandle(0,this.cates[0].id)
			},
			async leftClickHandle(index,id){
				this.active = index
				//获取右侧的数据
				const res = await this.$myrequest({
					url:'/api/getimages/'+id
				})
				this.secondDate = res.data.message
			},
			previewImg(current){
				const urls = this.secondDate.map(item=>{
					return item.img_url
				})
				uni.previewImage({
					current,
					urls
				})
			}
		},
		onLoad() {
			this.getPicsCate()
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}
	.text{
		font-size: 40rpx;
		text-align: center;
	}
	.pics {
		height: 100%;
		display: flex;

		.left {
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;

			view {
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}

			.active {
				background: $shop-color;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 530rpx;
			margin: 10rpx auto;
			.item{
				image{
					width: 525rpx;
					height: 525rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}

	}
</style>
